-
Notifications
You must be signed in to change notification settings - Fork 217
use Win32 file APIs and widePath for file ops to support long filenames #1004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@swift-ci test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this!
} | ||
if (RemoveDirectoryW(wpath.data())) { | ||
return 0; | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary } else {
. Just use }
and the rest of the body can follow.
2a26b43
to
e0c6ead
Compare
@swift-ci test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of minor nits, but looks good to me.
lib/Basic/PlatformUtility.cpp
Outdated
llvm::SmallVector<wchar_t, MAX_PATH> wPath; | ||
if (llvm::sys::path::widenPath(path, wPath)) | ||
return std::string(); | ||
CreateDirectoryW(wPath.data(), NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to log the error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a lot of logging... Are you thinking just a fprintf maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah ... at least we would have something to go on if it ever failed.
e0c6ead
to
3ff8d69
Compare
@swift-ci test |
3ff8d69
to
c9736f5
Compare
@swift-ci test |
c9736f5
to
bb4eef8
Compare
@swift-ci test |
@swift-ci please smoke test |
#else | ||
return ::rmdir(path); | ||
#endif | ||
} | ||
|
||
int sys::stat(const char *fileName, StatStruct *buf) { | ||
#if defined(_WIN32) | ||
return ::_stat(fileName, buf); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@compnerd Would it be simpler to use _wstat, _wrmdir, etc., vs the Win32 functions? They support long paths too, as they are just wrappers around Win32 anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so there would need some char to wchar_t conversion here to use those, so Im not sure it saves that much since the widePath API does this already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you might've misunderstood what I meant. I was suggesting that instead of writing thirty lines of code, you simply call:
llvm::SmallVector<wchar_t, MAX_PATH> wfilename;
if (llvm::sys::path::widenPath(fileName, wfilename)) {
errno = EINVAL;
return -1;
}
return ::_wstat(wfilename, buf);
...as opposed to GetFileAttributesExW and all the conversion ceremony that follows. I'm also concerned this is subtly changing behavior as you're filling in the stat info differently from how _stat and _wstat do it, now.
I think you should:
- Switch CreateDirectoryW to _wmkdir
- Switch RemoveDirectoryW to _wrmdir
- Switch GetFileAttributesExW to _wstat
- Switch DeleteFileW to _wunlink
That will ensure error handling and behavior is consistent with previously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do these _w functions accept the //?/ prefixed paths?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Microsoft implementation does support the NT style paths I believe but they are disjoint from Win32. e.g. usingSetEnvironmentVariableW
and wgetenv
would give unexpected results. I think that using win32 might unify some behaviors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do these _w functions accept the //?/ prefixed paths?
Like I said, they just wrap the underlying Win32 functions with a little ceremony on top. So by definition, yes. e.g. the implementation of _wmkdir literally just calls CreateDirectoryW and does nothing but that other than set errno to an appropriate value based on GetLastError.
ucrt's source is also available in the Windows SDK and you can inspect it.
e.g. usingSetEnvironmentVariableW and wgetenv would give unexpected results.
Environment is a little different than the other functions.
It seems like the windows-toolchain build failed after this commit. https://ci-external.swift.org/job/swift-main-windows-toolchain/1526 Looking at the commits that were part of the first failing run. This seemed like the most likely culprit given that it modifies a function called Pull request testing also seems blocked e.g https://ci-external.swift.org/view/Pull%20Request/job/swift-PR-windows/44356/ |
I mentioned this in the revert, but the issue here is that PR testing was testing tip rather than the PR itself. I'll edit this comment once that's fixed. EDIT: That should be fixed now. Worth checking the commit in the next PR run though 😅 |
No description provided.